<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>注册</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@1.6/lib/index.css">
		<script src="../../js/vue.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/ajax.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/vue-toasted.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/vant.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/listener_other.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/jquery-2.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="app">
			<head>
				<van-nav-bar  @click-left="onClickLeft" title="注册" left-text="返回" left-arrow id="a">
				</van-nav-bar>
			</head>
			<section>
				<van-cell-group>
				  <van-field name="nickName" id="nickName" v-model="nickName" clearable label="用户名" icon="question-o" placeholder="最多20个字">
				  </van-field>
					<van-field required clearable id="phone" label="手机号" name="phone" v-model="phone" icon="question-o" placeholder="请输入手机号">
					</van-field>
					<van-field center clearable label="短信验证码" v-model="code" name="code"  placeholder="请输入短信验证码" use-button-slot>
						<van-button slot="button" @click="getcode" size="small" type="primary">发送验证码</van-button>
					</van-field>
					<van-field  type="password" id="password" label="登录密码" v-model="password" name="password" placeholder="最少6位" required></van-field>
					<van-field  type="password" id="qrpassword" label="确认密码" placeholder="再次输入登录密码" required></van-field>
					<van-area :area-list="areaList" title="选择地区" v-model="districtCode" @confirm="confirm"></van-area>
				</van-cell-group>
			</section>
			<footer>
                <van-button type="warning" size="large" center @click="zhuce">立即注册</van-button>
			</footer>
		</div>
		<script>
			 Vue.use(Toasted);
			
			var vm = new Vue({
				el: "#app",
				data: {
					nickName:"",
					phone:"",
					code:"",
					password:"",
					code:"",
					areaList:{
						 province_list: {
						410000: '河南省',
					  },
					  city_list: {
						410500: '安阳市'
					  },
					  county_list: {
						410522: '安阳县'
					  }
					},
					districtCode:""
					
				},
				methods:{
					onClickLeft: function() {
						//plus.webview.open("login.html", "login");
						plus.webview.close(plus.webview.currentWebview(), "slide-out-left");
						console.log("返回个人页面");
					},
					getcode:function() {
						var pho=document.getElementById("phone").value;
						ajax({
							url: "http://dsapi.ysd3g.com/API/SendRegisterPhoneCode",
							dataType: "jsonp",
							data: {
								phone:pho
							},
							success: function(result) {
								if (result.Error) {
									vm.$toasted.error("您的手机号码不正确",{position:"bottom-center",duration:2000});
								}
								else{
									$.post('http://www.54cjk.cn/Gbook/getsend',{phone:vm.phone}, function (data) {
										vm.$toasted.success("您的验证码为"+data.Code,{position:"bottom-center",duration:5000});
										vm.code=data.Code;
										console.log(data);
									});
								}
							}
						})
					},
					zhuce:function(){
						var nickName=document.getElementById("nickName").value;
						var phone=document.getElementById("phone").value;
						var code=vm.code;
						var password=document.getElementById("password").value;
						var districtCode=vm.districtCode;
						var qrpassword=document.getElementById("qrpassword").value; 
						if(password==qrpassword){
							ajax({
								url: "http://dsapi.ysd3g.com/API/UserRegister",
								dataType: "jsonp",
								data: {
									 nickName:nickName,phone:phone,districtCode:410522,code:code,password:password//districtCode不是后台接口固定值
								},
								success: function(result) {
									console.log(result);
									if(result.Error){
										vm.$toasted.error("注册失败",{position:"bottom-center",duration:3000});
									}
									else{
										console.log(result);
										vm.$toasted.success("注册成功，三秒后为您跳转到登录页面",{position:"bottom-center",duration:3000});
										window.setTimeout(function() {
											plus.webview.open("login.html", "login");
										}, 3000);
									}
								}
							})
						}
						else{
							vm.$toasted.error("两次密码不一致",{position:"bottom-center",duration:3000});
						}
					},
					confirm:function(res){
						console.log(res);
						console.log(res[2].code);
						vm.districtCode=res[2].code;
					}
				} 
			})
		</script>

	</body>
</html>
